from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.renderers import JSONRenderer
from app.lib.jwtUtils import Jwt, verifty_token
import json

class Login(APIView):
  renderer_classes = [JSONRenderer]

  def post(self, request):
    req_params = json.loads(request.body)

    token = Jwt.encode({
      "username": req_params['username'],
      "password": req_params['password']
    })

    return Response({
      'code': '200',
      'data': {
        'token': token
      }
    }, content_type="application/json")


class UserInfo(APIView):
  renderer_classes = [JSONRenderer]

  @verifty_token()
  def get(self, request, payload):
    print('用户信息', payload)

    return Response('用户信息接口', content_type="application/json")
